﻿//#define TEST_DB
#define Template_DB

using CommonBaseEntityDb.Db;

try
{
#if TEST_DB
    DbClient dbClient = new DbClient(@"Data Source=.; Initial Catalog=Test; User Id=sa; Password=123456; Pooling=true; Max Pool Size=100; Encrypt=True; TrustServerCertificate=True;");
#elif Template_DB
    DbClient dbClient = new DbClient(@"Data Source=.; Initial Catalog=Template; User Id=sa; Password=123456; Pooling=true; Max Pool Size=100; Encrypt=True; TrustServerCertificate=True;");
#endif

    string tableName = "Users",
           filePath = @"D:\work\Vue3Net8\Template_Api\Model\Entity",
           classNamespace = "Model.Entity";

    dbClient.instance.Open();
    
    dbClient.instance.DbFirst.IsCreateAttribute().StringNullable().IsCreateDefaultValue()
    .SettingNamespaceTemplate(old =>
    {
        return @"using Enums;
using System.ComponentModel;
";
    })
    .SettingClassDescriptionTemplate(old =>
    {
        return @"    /// <summary>
    /// {ClassDescription}    /// </summary>
    [Serializable]
    [Tenant(SqlConfigIdEnum.Test)]    
    [Description(""{ClassDescription}"")]";
    })
    .SettingPropertyDescriptionTemplate(old =>
    {
        return @"           /// <summary>
           /// Desc:{PropertyDescription}
           /// Default:{DefaultValue}
           /// Nullable:{IsNullable}
           /// </summary>
           [Description(""{PropertyDescription}"")]";
    })
    .Where(it => it == tableName)
    .CreateClassFile(filePath, classNamespace);

    dbClient.instance.Close();

    Console.WriteLine("生成完成");
    Console.ReadLine();
}
catch (Exception ex)
{
    Console.WriteLine($"生成失败！失败原因：{ex.Message}");
    Console.ReadLine();
}
